/**
 * <pre>
 * ss-fire-collector / JobStateVO.java
 * collector.task Class
 * JobStateVO
 * <br>
 * 
 * <br>
 * @author ytjeong/apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 18.
 * </pre>
 */
package collector.task;

import java.util.Date;

import net.apexcns.core.util.StringUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import collector.core.CollectConstants;
import collector.core.util.DateUtil;


/**
 * <pre>
 * Class : collector.task.JobStateVO / JobStateVO.java
 * 	Define Class Object : 작업 처리 상태 및 결과 저장 객체
 * 
 * 	작업 상태 관련 정보의 Cycle
 * 	1. Past > Current > Next
 * 	
 * 	
 * 	
 * <br>
 * </pre>
 * 
 * @author ytjeong / apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 18.
 */

public class JobStateVO {
	@SuppressWarnings("unused")
	private static Logger _log = LoggerFactory.getLogger(JobStateVO.class);
	@SuppressWarnings("unused")
	private static final String _LogPrefixStr = CollectConstants.LOGGER_MODULE_NAME_SMC + CollectConstants.LOGGER_MODULE_NAME_AFTFIX;//"test Log> ";
	
	public JobStateVO() {
		super();
	}

	public JobStateVO(String jobIDs) {
		super();
		this.jobIDs = jobIDs;
	}

	protected String point = null; // point

	protected String jobIDs = null; // 작업 ID
	protected Date scheduleTime = null; // 현재 스케줄 시간
	protected Date registScheduleTime = null; // 초기 스케줄 등록 시간
	protected Date completeScheduleTime = null; // 스케줄 완료 시간

	protected int jobDurationValue = 1; // 작업 처리를 위한 조건 시간 간격
	protected String jobCondStartTime = null; // 작업 처리를 위한 조건 시간
	protected String jobCondEndTime = null; // 작업 처리를 위한 조건 시간

	protected boolean jobAuto = true; // 자동 처리 여부

	protected String jobState = null; // 작업 상태

	protected String jobResult = null; // 작업 처리 결과, 작업 상태가 'Done' 인 경우 'Succ' 또는 'Fail'를 갖는다.
	protected int jobResultCode = 0; // 작업 결과 코드
	protected String jobResultMsg = null; // 작업 결과 메세지 (오류의 경우 오류 메세지)

	protected float processTime = 0; // 작업 처리에 걸린 시간
	protected float rsTime = 0; // DB Data fetch에 걸린 시간
	protected float fileMakeTime = 0; // Data File 생성에 걸린 시간
	protected float fileCopyTime = 0; // Data File 복제에 걸린 시간
	protected long totalRecordCount = 0; // Succ 결과에 따른 처리 레코드 수
	protected int totalFileCount = 0; // Succ 결과에 따른 처리 파일 수

	/**
	 * <pre>
	 * Method : JobStateVO.setRetCodeMsg()
	 * 
	 * <br>
	 * 	return type of void
	 * <br>
	 * @param jobResultCode
	 * @param jobResultMsg
	 * </pre>
	 */
	public void setJobResultCodeMsg(int jobResultCode, String jobResultMsg) {
		this.jobResultCode = jobResultCode;
		this.jobResultMsg = jobResultMsg;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobIDs()
	 * 	to get jobIDs
	 * <br> 
	 * @return the jobIDs : type of String
	 * </pre>
	 */
	public String getJobIDs() {
		return jobIDs;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobIDs()
	 * 	to set jobIDs 
	 * <br> 
	 * @param jobIDs : type of String
	 * </pre>
	 */
	public void setJobIDs(String jobIDs) {
		this.jobIDs = jobIDs;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getScheduleTime()
	 * 	to get scheduleTime
	 * <br> 
	 * @return the scheduleTime : type of Date
	 * </pre>
	 */
	public Date getScheduleTime() {
		return scheduleTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setScheduleTime()
	 * 	to set scheduleTime 
	 * <br> 
	 * @param scheduleTime : type of Date
	 * </pre>
	 */
	public void setScheduleTime(Date scheduleTime) {
		this.scheduleTime = scheduleTime;
	}
	
	
	/** <pre>
	 * Method : JobStateVO.getJobDurationValue()
	 * 	to get jobDurationValue
	 * <br> 
	 * @return the jobDurationValue : type of int
	 * </pre>
	 */
	public int getJobDurationValue() {
		return jobDurationValue;
	}

	/** <pre>
	 * Method : JobStateVO.setJobDurationValue()
	 * 	to set jobDurationValue
	 * <br> 
	 * @return the jobDurationValue : type of int
	 * </pre>
	 */
	public void setJobDurationValue(int jobDurationValue) {
		this.jobDurationValue = jobDurationValue;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobCondStartTime()
	 * 	to get jobCondStartTime
	 * <br> 
	 * @return the jobCondStartTime : type of String
	 * </pre>
	 */
	public String getJobCondStartTime() {
		return jobCondStartTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobCondStartTime()
	 * 	to set jobCondStartTime 
	 * <br> 
	 * @param jobCondStartTime : type of String
	 * </pre>
	 */
	public void setJobCondStartTime(String jobCondStartTime) {
		this.jobCondStartTime = jobCondStartTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobCondEndTime()
	 * 	to get jobCondEndTime
	 * <br> 
	 * @return the jobCondEndTime : type of String
	 * </pre>
	 */
	public String getJobCondEndTime() {
		return jobCondEndTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobCondEndTime()
	 * 	to set jobCondEndTime 
	 * <br> 
	 * @param jobCondEndTime : type of String
	 * </pre>
	 */
	public void setJobCondEndTime(String jobCondEndTime) {
		this.jobCondEndTime = jobCondEndTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.isJobAuto()
	 * 	to get jobAuto
	 * <br> 
	 * @return the jobAuto : type of boolean
	 * </pre>
	 */
	public boolean isJobAuto() {
		return jobAuto;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobAuto()
	 * 	to set jobAuto 
	 * <br> 
	 * @param jobAuto : type of boolean
	 * </pre>
	 */
	public void setJobAuto(boolean jobAuto) {
		this.jobAuto = jobAuto;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobState()
	 * 	to get jobState
	 * <br> 
	 * @return the jobState : type of String
	 * </pre>
	 */
	public String getJobState() {
		return jobState;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobState()
	 * 	to set jobState 
	 * <br> 
	 * @param jobState : type of String
	 * </pre>
	 */
	public void setJobState(String jobState) {
		this.jobState = jobState;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobResult()
	 * 	to get jobResult
	 * <br> 
	 * @return the jobResult : type of String
	 * </pre>
	 */
	public String getJobResult() {
		return jobResult;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobResult()
	 * 	to set jobResult 
	 * <br> 
	 * @param jobResult : type of String
	 * </pre>
	 */
	public void setJobResult(String jobResult) {
		this.jobResult = jobResult;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobResultCode()
	 * 	to get jobResultCode
	 * <br> 
	 * @return the jobResultCode : type of int
	 * </pre>
	 */
	public int getJobResultCode() {
		return jobResultCode;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobResultCode()
	 * 	to set jobResultCode 
	 * <br> 
	 * @param jobResultCode : type of int
	 * </pre>
	 */
	public void setJobResultCode(int jobResultCode) {
		this.jobResultCode = jobResultCode;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getJobResultMsg()
	 * 	to get jobResultMsg
	 * <br> 
	 * @return the jobResultMsg : type of String
	 * </pre>
	 */
	public String getJobResultMsg() {
		return jobResultMsg;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setJobResultMsg()
	 * 	to set jobResultMsg 
	 * <br> 
	 * @param jobResultMsg : type of String
	 * </pre>
	 */
	public void setJobResultMsg(String jobResultMsg) {
		this.jobResultMsg = jobResultMsg;
	}
	
	/**
	 * <pre>
	 * Method : JobStateVO.getProcessTime()
	 * 	to get processTime
	 * <br> 
	 * @return the processTime : type of float
	 * </pre>
	 */
	public float getProcessTime() {

		if (processTime == 0)
			this.processTime = this.rsTime
					+ this.fileMakeTime + this.fileCopyTime;
		return processTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setProcessTime()
	 * 	to set processTime 
	 * <br> 
	 * @param processTime : type of float
	 * </pre>
	 */
	public void setProcessTime(float processTime) {
		this.processTime = processTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getRsTime()
	 * 	to get rsTime
	 * <br> 
	 * @return the rsTime : type of float
	 * </pre>
	 */
	public float getRsTime() {
		return rsTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setRsTime()
	 * 	to set rsTime 
	 * <br> 
	 * @param rsTime : type of float
	 * </pre>
	 */
	public void setRsTime(float rsTime) {
		this.rsTime = rsTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getFileMakeTime()
	 * 	to get fileMakeTime
	 * <br> 
	 * @return the fileMakeTime : type of float
	 * </pre>
	 */
	public float getFileMakeTime() {
		return fileMakeTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setFileMakeTime()
	 * 	to set fileMakeTime 
	 * <br> 
	 * @param fileMakeTime : type of float
	 * </pre>
	 */
	public void setFileMakeTime(float fileMakeTime) {
		this.fileMakeTime = fileMakeTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getFileCopyTime()
	 * 	to get fileCopyTime
	 * <br> 
	 * @return the fileCopyTime : type of float
	 * </pre>
	 */
	public float getFileCopyTime() {
		return fileCopyTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setFileCopyTime()
	 * 	to set fileCopyTime 
	 * <br> 
	 * @param fileCopyTime : type of float
	 * </pre>
	 */
	public void setFileCopyTime(float fileCopyTime) {
		this.fileCopyTime = fileCopyTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getTotalRecordCount()
	 * 	to get totalRecordCount
	 * <br> 
	 * @return the totalRecordCount : type of long
	 * </pre>
	 */
	public long getTotalRecordCount() {
		return totalRecordCount;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setTotalRecordCount()
	 * 	to set totalRecordCount 
	 * <br> 
	 * @param totalRecordCount : type of long
	 * </pre>
	 */
	public void setTotalRecordCount(long totalRecordCount) {
		this.totalRecordCount = totalRecordCount;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.getTotalFileCount()
	 * 	to get totalFileCount
	 * <br> 
	 * @return the totalFileCount : type of int
	 * </pre>
	 */
	public int getTotalFileCount() {
		return totalFileCount;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setTotalFileCount()
	 * 	to set totalFileCount 
	 * <br> 
	 * @param totalFileCount : type of int
	 * </pre>
	 */
	public void setTotalFileCount(int totalFileCount) {
		this.totalFileCount = totalFileCount;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 * 
	 * Method : collector.task.JobStateVO.toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("JobStateVO [jobIDs=").append(jobIDs)
				.append(", scheduleTime=").append(scheduleTime)
				.append(", registScheduleTime=").append(registScheduleTime)
				.append(", completeScheduleTime=").append(completeScheduleTime)
				.append(", jobDurationValue=").append(jobDurationValue)
				.append(", jobCondStartTime=").append(jobCondStartTime)
				.append(", jobCondEndTime=").append(jobCondEndTime)
				.append(", jobAuto=").append(jobAuto)
				.append(", jobState=").append(jobState)
				.append(", jobResult=").append(jobResult)
				.append(", jobResultCode=").append(jobResultCode)
				.append(", jobResultMsg=").append(jobResultMsg)
				.append(", processTime=").append(processTime)
				.append(", rsTime=").append(rsTime)
				.append(", fileMakeTime=").append(fileMakeTime)
				.append(", fileCopyTime=").append(fileCopyTime)
				.append(", totalRecordCount=").append(totalRecordCount)
				.append(", totalFileCount=").append(totalFileCount).append("]");
		return builder.toString();
	}

	/**
	 * <pre>
	 * Method : JobStateVO.toStringDisplay()
	 * 	작업 정보의 formated 출력을 위한 Display 스트링 리턴
	 * <br>
	 * 	return type of String
	 * <br>
	 * @return 
	 * </pre>
	 */
	public String toStringDisplay() {
		StringBuilder builder = new StringBuilder();
//		builder.append("JobStateVO [jobIDs=").append(jobIDs)
//				.append(", scheduleTime=").append(scheduleTime)
//				.append(", registScheduleTime=").append(registScheduleTime)
//				.append(", jobCondStartTime=").append(jobCondStartTime)
//				.append(", jobCondEndTime=").append(jobCondEndTime)
//				.append(", jobAuto=").append(jobAuto).append(", jobState=")
//				.append(jobState).append(", jobResult=").append(jobResult)
//				.append(", jobResultCode=").append(jobResultCode)
//				.append(", jobResultMsg=").append(jobResultMsg)
//				.append(", processTime=").append(processTime)
//				.append(", rsTime=").append(rsTime).append(", listingTime=")
//				.append(listingTime).append(", fileMakeTime=")
//				.append(fileMakeTime).append(", fileCopyTime=")
//				.append(fileCopyTime).append(", totalRecordCount=")
//				.append(totalRecordCount).append(", totalFileCount=")
//				.append(totalFileCount).append("]");
		
		builder.append("").append(jobState).append(" :: ").append(jobIDs).append(" job is ").append(jobResult).append(" [ total : ").append(totalRecordCount).append(" rec, ").append(totalFileCount).append(" files (").append(processTime).append("s) ]").append("\n")
		.append("\t\t").append(" job Time").append(" rs(").append(rsTime).append("s) > file make(").append(fileMakeTime).append("s) >> file copy(").append(fileCopyTime).append("s)").append("\n")
		.append("\t\t").append(" job Info").append(" jobState(").append(jobState).append(") schTime(").append(scheduleTime).append(") condStart(").append(jobCondStartTime).append(") condEnd(").append(jobCondEndTime).append(") ").append("\n")
		.append("\t\t").append(" job Detail").append(" jobAuto(").append(jobAuto).append(") regTime(").append(registScheduleTime).append(") resCode(").append(jobResultCode).append(") resMsg(").append(jobResultMsg).append(")");
		return builder.toString();
	}
	
	public String toStringPast() {
		StringBuilder builder = new StringBuilder();
		builder.append("JobStateVO [JobID=").append(jobIDs)
				.append(", State=").append(jobState)
				.append(", Start=").append(DateUtil.dateToYmd(scheduleTime,"yyyy-MM-dd HH:mm:ss"))
				.append(", End=").append(DateUtil.dateToYmd(completeScheduleTime,"yyyy-MM-dd HH:mm:ss"))
				.append(", From=").append(DateUtil.getFmtDateTime(jobCondStartTime, 14))
				.append(", To=").append(DateUtil.getFmtDateTime(jobCondEndTime, 14))
				.append(", Result=").append(jobResult)
				.append(", Total Record=").append(totalRecordCount)
				.append(", Total Time=").append(processTime).append("]");
		
		return builder.toString();
	}

	public String toStringCurrent() {
		StringBuilder builder = new StringBuilder();
		builder.append("JobStateVO [JobID=").append(jobIDs)
				.append(", State=").append(jobState)
				.append(", Start=").append(DateUtil.dateToYmd(scheduleTime,"yyyy-MM-dd HH:mm:ss"))
				.append(", End=???")
				.append(", From=").append(DateUtil.getFmtDateTime(jobCondStartTime, 14))
				.append(", To=").append(DateUtil.getFmtDateTime(jobCondEndTime, 14))
				.append(", Result=???")
				.append(", Total Record=???")
				.append(", Total Time=???").append("]");
		
		return builder.toString();
	}
		
	public String toStringNext() {
		StringBuilder builder = new StringBuilder();
		builder.append("JobStateVO [JobID=").append(jobIDs)
				.append(", State=").append(jobState)
				.append(", Start=").append(DateUtil.dateToYmd(scheduleTime,"yyyy-MM-dd HH:mm:ss"))
				.append(", End=???")
				.append(", From=").append(DateUtil.getFmtDateTime(jobCondStartTime, 14))
				.append(", To=").append(DateUtil.getFmtDateTime(jobCondEndTime, 14))
				.append(", To=???")
				.append(", Result=???")
				.append(", Total Record=???")
				.append(", Total Time=???").append("]");
		
		return builder.toString();
	}

	/**
	 * <pre>
	 * Method : JobStateVO.updateJobStateVo()
	 * 		바뀌어진 정보를 비교하여 갱신합니다.
	 * <br>
	 * 	return type of void
	 * <br>
	 * @param pjsVo
	 * </pre>
	 */
	public void updateJobStateVo(JobStateVO pjsVo) {
		if (StringUtil.isNotNull(pjsVo.getJobIDs()))
			jobIDs = pjsVo.getJobIDs();
		if (pjsVo.getScheduleTime() != null)
			scheduleTime = pjsVo.getScheduleTime();
		if (pjsVo.getRegistScheduleTime() != null)
			registScheduleTime = pjsVo.getRegistScheduleTime();
		if (pjsVo.getCompleteScheduleTime() != null)
			completeScheduleTime = pjsVo.getCompleteScheduleTime();
		if (StringUtil.isNotNull(pjsVo.getJobCondStartTime()))
			jobCondStartTime = pjsVo.getJobCondStartTime();
		if (StringUtil.isNotNull(pjsVo.getJobCondEndTime()))
			jobCondEndTime = pjsVo.getJobCondEndTime();
		if (isJobAuto() != pjsVo.isJobAuto())
			jobAuto = pjsVo.isJobAuto();
		if (StringUtil.isNotNull(pjsVo.getJobState()))
			jobState = pjsVo.getJobState();
		if (StringUtil.isNotNull(pjsVo.getJobResult()))
			jobResult = pjsVo.getJobResult();
		if (pjsVo.getJobResultCode() != 0)
			jobResultCode = pjsVo.getJobResultCode();
		if (StringUtil.isNotNull(pjsVo.getJobResultMsg()))
			jobResultMsg = pjsVo.getJobResultMsg();
		if (pjsVo.getProcessTime() != 0)
			processTime = pjsVo.getProcessTime();
		if (pjsVo.getRsTime() != 0)
			rsTime = pjsVo.getRsTime();
		if (pjsVo.getFileMakeTime() != 0)
			fileMakeTime = pjsVo.getFileMakeTime();
		if (pjsVo.getFileCopyTime() != 0)
			fileCopyTime = pjsVo.getFileCopyTime();
		if (pjsVo.getTotalRecordCount() != 0)
			totalRecordCount = pjsVo.getTotalRecordCount();
		if (pjsVo.getTotalFileCount() != 0)
			totalFileCount = pjsVo.getTotalFileCount();
	}

	/** <pre>
	 * Method : JobStateVO.getPoint()
	 * 	to get point
	 * <br> 
	 * @return the point : type of String
	 * </pre>
	 */
	public String getPoint() {
	    return point;
	}

	/** <pre>
	 * Method : JobStateVO.setPoint()
	 * 	to set point 
	 * <br> 
	 * @param point : type of String
	 * </pre>
	 */
	public void setPoint(String point) {
	    this.point = point;
	}
	
	/**
	 * <pre>
	 * Method : JobStateVO.getRegistScheduleTime()
	 * 	to get registScheduleTime
	 * <br> 
	 * @return the registScheduleTime : type of Date
	 * </pre>
	 */
	public Date getRegistScheduleTime() {
		return registScheduleTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setRegistScheduleTime()
	 * 	to set registScheduleTime 
	 * <br> 
	 * @param registScheduleTime : type of Date
	 * </pre>
	 */
	public void setRegistScheduleTime(Date registScheduleTime) {
		this.registScheduleTime = registScheduleTime;
	}
	
	/**
	 * <pre>
	 * Method : JobStateVO.getCompleteScheduleTime()
	 * 	to get completeScheduleTime
	 * <br> 
	 * @return the completeScheduleTime : type of Date
	 * </pre>
	 */
	public Date getCompleteScheduleTime() {
		return completeScheduleTime;
	}

	/**
	 * <pre>
	 * Method : JobStateVO.setCompleteScheduleTime()
	 * 	to set completeScheduleTime 
	 * <br> 
	 * @param completeScheduleTime : type of Date
	 * </pre>
	 */
	public void setCompleteScheduleTime(Date completeScheduleTime) {
		this.completeScheduleTime = completeScheduleTime;
	}

	public void setFailDoneResult(int retCode, String retMsg) {
		setJobResult(CollectConstants.CODE_JOB_RESULT_FAIL);
		setJobResultCodeMsg(retCode, retMsg);
		setCompleteScheduleTime(DateUtil.now());
		setJobState(CollectConstants.CODE_JOB_STATE_DONE);
	}

	public void setSuccDoneResult(int retCode, String retMsg) {
		setJobResult(CollectConstants.CODE_JOB_RESULT_SUCC);
		setJobResultCodeMsg(retCode, retMsg);
		setCompleteScheduleTime(DateUtil.now());
		setJobState(CollectConstants.CODE_JOB_STATE_DONE);
	}
	
	public void getJobStateLog() {
		
	}
}
